package com.sx.manage.controller.profit;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.profit.MCompanyprofitWebService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.profit.MProfitForm;
import com.sx.model.manage.mybatis.vo.profit.MProfitVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultObjectVO;

/**
 *
 * @author Administrator
 * @version 1.0.0 Wed Jul 19 00:00:00 CST 2017
 */
@Controller
@RequestMapping("/company_profit")
public class MCompanyprofitController extends MBaseController {
	/*** 日志 */
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Resource(name = "companyprofitWebService")
	private MCompanyprofitWebService companyprofitServiceImpl;

	public Logger getLogger() {
		return logger;
	}

	public void setLogger(Logger logger) {
		this.logger = logger;
	}

	public MCompanyprofitWebService getCompanyprofitServiceImpl() {
		return companyprofitServiceImpl;
	}

	public void setCompanyprofitServiceImpl(MCompanyprofitWebService companyprofitServiceImpl) {
		this.companyprofitServiceImpl = companyprofitServiceImpl;
	}

	/** 数据列表列表 */
	@RequestMapping(value = "list_view")
	public ViewAndModel list_view(MProfitForm form) {
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("profit/company/profitRuleList");
		return modelView;
	}

	/** 添加界面跳转 */
	@RequestMapping(value = "view_add")
	public ViewAndModel view_add(MProfitForm form) {
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("profit/company/addProfitRule");
		return modelView;
	}

	/** 编辑界面跳转 */
	@RequestMapping(value = "view_edit/{id}")
	public ViewAndModel view_edit(@PathVariable Long id, String company_type) {
		ViewAndModel modelView = new ViewAndModel(request, cache);
		modelView.setViewName("profit/company/editProfitRule");
		ResultObjectVO<MProfitVO> result = companyprofitServiceImpl.queryById(id, company_type);
		modelView.addObject("objVO", result.getObjVo());
		return modelView;
	}

	/** 数据保存 */
	@RequestMapping(value = "save")
	@ResponseBody
	public ResultBooleanVO save(MProfitForm form, BindingResult errors) {
		String error = this.fieldValidate(form, errors);
		if (null != error) {
			return new ResultBooleanVO(false, null, error);
		}
		return companyprofitServiceImpl.save(form, loginConsumer());
	}

	/** 根据id删除数据 */
	@RequestMapping(value = "delete")
	@ResponseBody
	public ResultBooleanVO delete(Long[] ids, String company_type) {
		return companyprofitServiceImpl.deleteById(ids, company_type, loginConsumer());
	}

	/** 翻页信息获取 */
	@RequestMapping(value = "page")
	@ResponseBody
	public ResultListVO<MProfitVO> page(MProfitForm form) {
		return companyprofitServiceImpl.queryPage(form);
	}

	/**** 启用 **/
	@RequestMapping(value = "enable/{id}")
	@ResponseBody
	public ResultBooleanVO enable(@PathVariable Long id, String company_type) {
		return companyprofitServiceImpl.isShow(company_type, id, loginConsumer());
	}

	/**** 禁用 **/
	@RequestMapping(value = "disable/{id}")
	@ResponseBody
	public ResultBooleanVO disable(@PathVariable Long id, String company_type) {
		return companyprofitServiceImpl.isNotShow(company_type, id, loginConsumer());
	}

} // end class